{% extends "base.html" %}

{% block title %}首页 - 校园摄影投票系统{% endblock %}

{% block content %}
    <h1 class="mb-4">最新摄影作品</h1>

    <div class="row">
        {% for photo in photos.items %}
        <div class="col-md-4 mb-4">
            <div class="card h-100">
                <a href="{{ url_for('main.photo_detail', photo_id=photo.id) }}">
                    <img src="{{ url_for('static', filename='uploads/' + photo.thumbnail) }}" 
                         class="card-img-top" alt="{{ photo.title }}"/>
                </a>
                <div class="card-body">
                    <h5 class="card-title">{{ photo.title }}</h5>
                    <p class="card-text text-muted">
                        作者: <a href="{{ url_for('main.user_profile', username=photo.author.username) }}">
                            {{ photo.author.username }}
                        </a>
                    </p>
                    <p class="card-text">
                        <small class="text-muted">{{ photo.vote_count }} 票</small>
                    </p>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>

    <!-- 分页导航 -->
    <nav aria-label="Page navigation">
        <ul class="pagination justify-content-center">
            {% if photos.has_prev %}
            <li class="page-item">
                <a class="page-link" href="{{ url_for('main.index', page=photos.prev_num) }}">上一页</a>
            </li>
            {% endif %}

            {% for page_num in photos.iter_pages() %}
                {% if page_num %}
                    <li class="page-item {% if page_num == photos.page %}active{% endif %}">
                        <a class="page-link" href="{{ url_for('main.index', page=page_num) }}">{{ page_num }}</a>
                    </li>
                {% else %}
                    <li class="page-item disabled">
                        <span class="page-link">...</span>
                    </li>
                {% endif %}
            {% endfor %}

            {% if photos.has_next %}
            <li class="page-item">
                <a class="page-link" href="{{ url_for('main.index', page=photos.next_num) }}">下一页</a>
            </li>
            {% endif %}
        </ul>
    </nav>
{% endblock %}